home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / settaskpri.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  2KB  |  108 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: settaskpri.c,v 1.4 1996/08/13 13:56:08 digulla Exp $
  4.     $Log: settaskpri.c,v $
  5.     Revision 1.4  1996/08/13 13:56:08  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:20  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang: english
  15. */
  16. #include <exec/execbase.h>
  17. #include <aros/libcall.h>
  18.  
  19. /*****************************************************************************
  20.  
  21.     NAME */
  22.     #include <clib/exec_protos.h>
  23.  
  24.     __AROS_LH2(BYTE, SetTaskPri,
  25.  
  26. /*  SYNOPSIS */
  27.     __AROS_LHA(struct Task *, task,      A1),
  28.     __AROS_LHA(LONG,          priority,  D0),
  29.  
  30. /*  LOCATION */
  31.     struct ExecBase *, SysBase, 50, Exec)
  32.  
  33. /*  FUNCTION
  34.     Change the priority of a given task. As a general rule the higher
  35.     the priority the more CPU time a task gets. Useful values are within
  36.     -127 to 5.
  37.  
  38.     INPUTS
  39.     task     - Pointer to task structure.
  40.     priority - New priority of the task.
  41.  
  42.     RESULT
  43.     Old task priority.
  44.  
  45.     NOTES
  46.  
  47.     EXAMPLE
  48.  
  49.     BUGS
  50.  
  51.     SEE ALSO
  52.  
  53.     INTERNALS
  54.  
  55.     HISTORY
  56.  
  57. ******************************************************************************/
  58. {
  59.     __AROS_FUNC_INIT
  60.  
  61.     BYTE old;
  62.  
  63.     /* Always Disable() when doing something with task lists. */
  64.     Disable();
  65.  
  66.     /* Get returncode */
  67.     old=task->tc_Node.ln_Pri;
  68.  
  69.     /* Set new value. */
  70.     task->tc_Node.ln_Pri=priority;
  71.  
  72.     /* Check if the task is willing to run. */
  73.     if(task->tc_State!=TS_WAIT)
  74.     {
  75.     /* If it is in the ready list remove and reinsert it. */
  76.     if(task->tc_State==TS_READY)
  77.     {
  78.         Remove(&task->tc_Node);
  79.         Enqueue(&SysBase->TaskReady,&task->tc_Node);
  80.     }
  81.  
  82.     /*
  83.         I could check the task priorities here to determine if
  84.         the following is really necessary, but OTOH priority
  85.         changes are rare and the hassle isn't really worth it.
  86.     */
  87.  
  88.     /* Are taskswitches allowed? */
  89.     if(SysBase->TDNestCnt>=0||SysBase->IDNestCnt>0)
  90.         /* No. Store it for later. */
  91.         SysBase->AttnResched|=0x80;
  92.     else
  93.     {
  94.         /* Switches are allowed. Move the current task away. */
  95.         SysBase->ThisTask->tc_State=TS_READY;
  96.         Enqueue(&SysBase->TaskReady,&SysBase->ThisTask->tc_Node);
  97.  
  98.         /* And force a rescedule. */
  99.         Switch();
  100.     }
  101.     }
  102.  
  103.     /* All done. */
  104.     Enable();
  105.     return old;
  106.     __AROS_FUNC_EXIT
  107. } /* SetTaskPri */
  108.